const path = require('path')
const { defineConfig } = require('@vue/cli-service')
const AddAssetHtmlPlugin = require('add-asset-html-webpack-plugin')
const webpack = require('webpack')
const proxy = require('./config/proxy')

const publicPath = '/insure'
module.exports = defineConfig({
	transpileDependencies: true,
	outputDir: './dist',
	publicPath: process.env.VUE_APP_ORIGIN,
	css: {
		loaderOptions: {
			sass: {
				// 全局引入变量和 mixin
				additionalData: `
          @import "/src/styles/xr-theme.scss";
          @import "/src/styles/mixin.scss";
          @import "/src/styles/global/variable.scss";
        `
			}
		}
	},
	devServer: {
		// https: true,
		client: {
			overlay: false
		},
		proxy: {
			'/api': {
				target: proxy,
				changeOrigin: true
			},
			'/insure': {
				target: proxy,
				changeOrigin: true
			},
			'/img/': {
				target: proxy,
				changeOrigin: true
			},
			'/upload': {
				target: proxy,
				changeOrigin: true
			}
		}
	},
	configureWebpack: {
		plugins: [
			new webpack.DllReferencePlugin({
				context: process.cwd(),
				manifest: require('./public/dll/vendor-manifest.json')
			}),
			new webpack.DllReferencePlugin({
				context: process.cwd(),
				manifest: require('./public/dll/utils-manifest.json')
			}),
			new AddAssetHtmlPlugin([
				{
					filepath: path.join(__dirname, './public/dll/vendor.dll.js'),
					outputPath: 'dll', // 输出到 dist/dll
					publicPath: publicPath + '/dll' // HTML 中引用路径
				},
				{
					filepath: path.join(__dirname, './public/dll/utils.dll.js'),
					outputPath: 'dll', // 输出到 dist/dll
					publicPath: publicPath + '/dll' // HTML 中引用路径
				}
			])
		]
	}
})
